I. Motivation & Introduction

With over 27 million cases and 465,000 deaths, the COVID-19 pandemic has led to unprecedented public health challenges for healthcare providers and policymakers. For one, hospitals and other care facilities in the United States have struggled at various points to keep up with the increase in COVID-19 patients needing critical care. With rapid increases in case counts nationally, there is a need for leading indicator signals that can guide decision makers in proactively allocating health system resources and assisting policy makers in balancing public health safety with economic concerns.

The COVIDcast project is unique in that it includes a combination of multiple signals including public health surveys, mobility, doctors visits, hospitalizations, etc. Based on this available combination, we characterized whether Facebook community signals and doctors visits signals, publicly available through the COVIDcast data project, can be used as leading indicators for case counts at the county level.

source("LeadingIndicatorToolsVS.R")
library(covidcast)
## We encourage COVIDcast API users to register on our mailing list:
## https://lists.andrew.cmu.edu/mailman/listinfo/delphi-covidcast-api
## We'll send announcements about new data sources, package updates,
## server maintenance, and new features.
library(magrittr)
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.1     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x tidyr::extract()   masks magrittr::extract()
## x dplyr::filter()    masks stats::filter()
## x dplyr::lag()       masks stats::lag()
## x purrr::set_names() masks magrittr::set_names()
library(assertthat)
## 
## Attaching package: 'assertthat'
## The following object is masked from 'package:tibble':
## 
##     has_name
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
# fb_survey2 = get_and_prepare_signals(cases_deaths="case", 
#                                     start_day="2020-05-01", 
#                                     end_day="2021-01-31",  
#                                     indicator_source="fb-survey", 
#                                     indicator_signal="smoothed_hh_cmnty_cli", 
#                                     case_death_threshold = 2000,
#                                     indicator_threshold=80,
#                                     geo_type = "county")
#saveRDS(fb_survey2, file="fb_survey.RDS")
#saveRDS(hospitalizations, file="hospitalizations_deaths.RDS")

fb_survey2=readRDS(file="fb_survey.RDS")
hospitalizations=readRDS(file="hospitalizations_deaths.RDS")

#fb_survey=list("cases" = case_list[large_geos], "indicator" = indicator_list[large_geos])

#hospitalizations=get_and_prepare_signals(cases_deaths="death",
#                                         start_day="2020-05-01",
#                                         end_day="2021-01-31",
#                                         indicator_source = "hospital-admissions",
#                                         indicator_signal="smoothed_adj_covid19_from_claims",
#                                         case_death_threshold = 0,
#                                         indicator_threshold = 0,
#                                         geo_type = "county")
#names(hospitalizations)<-c("deaths","indicator")

Results: 1. FB Survey as a Leading Indicator for COVID-19 Cases

fb_survey_cases_indicator_list = get_increase_points(case_list = fb_survey2$cases, 
                                                     indicator_list = fb_survey2$indicator,
                                                    local_bandwidth = 12,
                                                    local_quantile_threshold = 0.75,
                                                    local_threshold=0.2,
                                                    local_period=0)
fb_survey_success_examples = get_success_examples(case_indicator_list = fb_survey_cases_indicator_list, success_window=14,
                                        min_success_window=3)
plot_list=vector("list", 5)
for(i in 1:length(plot_list))
{
  county_name = fb_survey_success_examples[[i]]
  plot_list[[i]]<-plot_signals(case_indicator_list = fb_survey_cases_indicator_list, county_fips = fb_survey_success_examples[[i]],
             ylab1 = "New COVID-19 Cases",
             ylab2="FB Survey", smooth_and_show_increase_point = TRUE)
  print(plot_list[[i]])

}

leadingness_dist=get_leading_indicator_day_distribution(success_examples = fb_survey_success_examples,final_cases_indicator_list = fb_survey_cases_indicator_list)
barplot(table(unlist(leadingness_dist)), xlab = "Leadingness (Day)", ylab = "Count", col = 'green', main = "How leading is the indicator?")

Bandwidth_For_Smoothing First_Derivative_Quantile_Threshold Min_Percent_Increase Period_Increase Success_Window Min_Success_Window Number_Success_Examples Most_Frequent_Leadingness Recall Precision F1_score
14 0.85 0.20 7 14 1 45 2 0.0466667 0.0484765 0.0475543
14 0.85 0.20 7 21 1 54 2 0.0466667 0.0484765 0.0475543
14 0.85 0.20 7 14 3 35 4 0.0466667 0.0484765 0.0475543
14 0.85 0.20 7 21 3 43 4 0.0466667 0.0484765 0.0475543
14 0.85 0.20 5 14 1 43 2 0.0439414 0.0455172 0.0447154
14 0.85 0.20 5 21 1 54 2 0.0439414 0.0455172 0.0447154
14 0.85 0.20 5 14 3 33 4 0.0439414 0.0455172 0.0447154
14 0.85 0.20 5 21 3 43 4 0.0439414 0.0455172 0.0447154
14 0.85 0.20 3 14 1 41 2 0.0426099 0.0441379 0.0433604
14 0.85 0.20 3 21 1 51 2 0.0426099 0.0441379 0.0433604
14 0.85 0.20 3 14 3 32 4 0.0426099 0.0441379 0.0433604
14 0.85 0.20 3 21 3 41 4 0.0426099 0.0441379 0.0433604
14 0.85 0.15 7 14 1 43 2 0.0426667 0.0433018 0.0429819
14 0.85 0.15 7 21 1 54 2 0.0426667 0.0433018 0.0429819
14 0.85 0.15 7 14 3 32 10 0.0426667 0.0433018 0.0429819
14 0.85 0.15 7 21 3 42 4 0.0426667 0.0433018 0.0429819
14 0.85 0.15 5 14 1 39 2 0.0386152 0.0391363 0.0388740
14 0.85 0.15 5 21 1 52 2 0.0386152 0.0391363 0.0388740
14 0.85 0.15 5 14 3 29 4 0.0386152 0.0391363 0.0388740
14 0.85 0.15 5 21 3 40 4 0.0386152 0.0391363 0.0388740
14 0.85 0.10 7 14 1 39 2 0.0360000 0.0361930 0.0360963
14 0.85 0.10 7 21 1 54 4 0.0360000 0.0361930 0.0360963
14 0.85 0.10 7 14 3 27 4 0.0360000 0.0361930 0.0360963
14 0.85 0.10 7 21 3 39 4 0.0360000 0.0361930 0.0360963
14 0.85 0.15 3 14 1 35 2 0.0346205 0.0350877 0.0348525
14 0.85 0.15 3 21 1 47 2 0.0346205 0.0350877 0.0348525
14 0.85 0.15 3 14 3 26 4 0.0346205 0.0350877 0.0348525
14 0.85 0.15 3 21 3 36 4 0.0346205 0.0350877 0.0348525
12 0.85 0.20 7 14 1 32 6 0.0334225 0.0346741 0.0340368
12 0.85 0.20 7 21 1 42 6 0.0334225 0.0346741 0.0340368
12 0.85 0.20 7 14 3 25 6 0.0334225 0.0346741 0.0340368
12 0.85 0.20 7 21 3 33 6 0.0334225 0.0346741 0.0340368
12 0.85 0.20 3 14 1 29 4 0.0319574 0.0331950 0.0325644
12 0.85 0.20 3 21 1 39 3 0.0319574 0.0331950 0.0325644
12 0.85 0.20 3 14 3 24 4 0.0319574 0.0331950 0.0325644
12 0.85 0.20 3 21 3 32 4 0.0319574 0.0331950 0.0325644
12 0.85 0.20 5 14 1 28 4 0.0306258 0.0318119 0.0312076
12 0.85 0.20 5 21 1 39 6 0.0306258 0.0318119 0.0312076
12 0.85 0.20 5 14 3 23 4 0.0306258 0.0318119 0.0312076
12 0.85 0.20 5 21 3 32 6 0.0306258 0.0318119 0.0312076
12 0.85 0.15 7 14 1 35 3 0.0307487 0.0311653 0.0309556
12 0.85 0.15 7 21 1 45 3 0.0307487 0.0311653 0.0309556
12 0.85 0.15 7 14 3 23 6 0.0307487 0.0311653 0.0309556
12 0.85 0.15 7 21 3 30 6 0.0307487 0.0311653 0.0309556
7 0.85 0.20 7 14 1 31 2 0.0300958 0.0316092 0.0308339
7 0.85 0.20 7 21 1 37 2 0.0300958 0.0316092 0.0308339
7 0.85 0.20 7 14 3 22 5 0.0300958 0.0316092 0.0308339
7 0.85 0.20 7 21 3 27 5 0.0300958 0.0316092 0.0308339
14 0.85 0.10 5 14 1 32 2 0.0306258 0.0307076 0.0306667
14 0.85 0.10 5 21 1 47 4 0.0306258 0.0307076 0.0306667
14 0.85 0.10 5 14 3 23 4 0.0306258 0.0307076 0.0306667
14 0.85 0.10 5 21 3 34 4 0.0306258 0.0307076 0.0306667
7 0.85 0.10 7 14 1 30 2 0.0287278 0.0297872 0.0292479
7 0.85 0.10 7 21 1 34 2 0.0287278 0.0297872 0.0292479
7 0.85 0.10 7 14 3 21 6 0.0287278 0.0297872 0.0292479
7 0.85 0.10 7 21 3 24 6 0.0287278 0.0297872 0.0292479
12 0.85 0.10 7 14 1 35 3 0.0280749 0.0282258 0.0281501
12 0.85 0.10 7 21 1 45 3 0.0280749 0.0282258 0.0281501
12 0.85 0.10 7 14 3 21 6 0.0280749 0.0282258 0.0281501
12 0.85 0.10 7 21 3 27 5 0.0280749 0.0282258 0.0281501
14 0.85 0.10 3 14 1 29 4 0.0279627 0.0280000 0.0279813
14 0.85 0.10 3 21 1 43 4 0.0279627 0.0280000 0.0279813
14 0.85 0.10 3 14 3 21 4 0.0279627 0.0280000 0.0279813
14 0.85 0.10 3 21 3 31 4 0.0279627 0.0280000 0.0279813
7 0.85 0.15 7 14 1 30 2 0.0273598 0.0284091 0.0278746
7 0.85 0.15 7 21 1 35 2 0.0273598 0.0284091 0.0278746
7 0.85 0.15 7 14 3 20 5 0.0273598 0.0284091 0.0278746
7 0.85 0.15 7 21 3 24 5 0.0273598 0.0284091 0.0278746
10 0.85 0.20 7 14 1 28 2 0.0268097 0.0276625 0.0272294
10 0.85 0.20 7 21 1 42 2 0.0268097 0.0276625 0.0272294
10 0.85 0.20 7 14 3 20 12 0.0268097 0.0276625 0.0272294
10 0.85 0.20 7 21 3 33 6 0.0268097 0.0276625 0.0272294
10 0.85 0.15 7 14 1 33 2 0.0268097 0.0271739 0.0269906
10 0.85 0.15 7 21 1 48 2 0.0268097 0.0271739 0.0269906
10 0.85 0.15 7 14 3 20 12 0.0268097 0.0271739 0.0269906
10 0.85 0.15 7 21 3 33 6 0.0268097 0.0271739 0.0269906
10 0.85 0.10 7 14 1 31 2 0.0254692 0.0257453 0.0256065
10 0.85 0.10 7 21 1 43 2 0.0254692 0.0257453 0.0256065
10 0.85 0.10 7 14 3 19 6 0.0254692 0.0257453 0.0256065
10 0.85 0.10 7 21 3 29 6 0.0254692 0.0257453 0.0256065
12 0.85 0.15 5 14 1 26 3 0.0239680 0.0242588 0.0241125
12 0.85 0.15 3 14 1 25 3 0.0239680 0.0242588 0.0241125
12 0.85 0.15 5 21 1 37 3 0.0239680 0.0242588 0.0241125
12 0.85 0.15 3 21 1 35 3 0.0239680 0.0242588 0.0241125
12 0.85 0.15 5 14 3 18 6 0.0239680 0.0242588 0.0241125
12 0.85 0.15 3 14 3 18 4 0.0239680 0.0242588 0.0241125
12 0.85 0.15 5 21 3 26 19 0.0239680 0.0242588 0.0241125
12 0.85 0.15 3 21 3 25 5 0.0239680 0.0242588 0.0241125
14 0.75 0.20 7 14 1 24 4 0.0213049 0.0216216 0.0214621
14 0.75 0.20 7 21 1 34 4 0.0213049 0.0216216 0.0214621
14 0.75 0.20 7 14 3 16 4 0.0213049 0.0216216 0.0214621
14 0.75 0.20 7 21 3 23 4 0.0213049 0.0216216 0.0214621
10 0.85 0.20 5 14 1 19 12 0.0199734 0.0205198 0.0202429
10 0.85 0.20 5 21 1 32 6 0.0199734 0.0205198 0.0202429
10 0.85 0.20 5 14 3 15 12 0.0199734 0.0205198 0.0202429
10 0.85 0.20 5 21 3 26 6 0.0199734 0.0205198 0.0202429
14 0.75 0.20 5 14 1 23 4 0.0199734 0.0202703 0.0201207
14 0.75 0.20 3 14 1 23 4 0.0199734 0.0202703 0.0201207
14 0.75 0.20 5 21 1 32 4 0.0199734 0.0202703 0.0201207
14 0.75 0.20 3 21 1 32 4 0.0199734 0.0202703 0.0201207
14 0.75 0.20 5 14 3 15 4 0.0199734 0.0202703 0.0201207
14 0.75 0.20 3 14 3 15 4 0.0199734 0.0202703 0.0201207
14 0.75 0.20 5 21 3 21 4 0.0199734 0.0202703 0.0201207
14 0.75 0.20 3 21 3 21 4 0.0199734 0.0202703 0.0201207
14 0.75 0.15 7 14 1 21 2 0.0186418 0.0186916 0.0186667
14 0.75 0.15 7 21 1 31 3 0.0186418 0.0186916 0.0186667
14 0.75 0.15 7 14 3 14 6 0.0186418 0.0186916 0.0186667
14 0.75 0.15 7 21 3 21 6 0.0186418 0.0186916 0.0186667
12 0.85 0.10 5 14 1 24 4 0.0186418 0.0186418 0.0186418
14 0.75 0.10 7 14 1 19 2 0.0186418 0.0186418 0.0186418
12 0.85 0.10 5 21 1 33 3 0.0186418 0.0186418 0.0186418
14 0.75 0.10 7 21 1 24 2 0.0186418 0.0186418 0.0186418
12 0.85 0.10 5 14 3 14 4 0.0186418 0.0186418 0.0186418
14 0.75 0.10 7 14 3 14 5 0.0186418 0.0186418 0.0186418
12 0.85 0.10 5 21 3 19 4 0.0186418 0.0186418 0.0186418
14 0.75 0.10 7 21 3 18 4 0.0186418 0.0186418 0.0186418
12 0.85 0.10 3 14 1 20 4 0.0173103 0.0173103 0.0173103
12 0.85 0.10 3 21 1 27 4 0.0173103 0.0173103 0.0173103
12 0.85 0.10 3 14 3 13 4 0.0173103 0.0173103 0.0173103
12 0.85 0.10 3 21 3 16 10 0.0173103 0.0173103 0.0173103
7 0.85 0.20 5 14 1 16 2 0.0159787 0.0161943 0.0160858
7 0.85 0.20 5 21 1 23 5 0.0159787 0.0161943 0.0160858
7 0.85 0.20 5 14 3 12 5 0.0159787 0.0161943 0.0160858
7 0.85 0.20 5 21 3 18 5 0.0159787 0.0161943 0.0160858
14 0.75 0.15 5 14 1 19 2 0.0159787 0.0160214 0.0160000
10 0.85 0.15 5 14 1 17 3 0.0159787 0.0160214 0.0160000
14 0.75 0.15 5 21 1 28 2 0.0159787 0.0160214 0.0160000
10 0.85 0.15 5 21 1 27 3 0.0159787 0.0160214 0.0160000
14 0.75 0.15 5 14 3 12 6 0.0159787 0.0160214 0.0160000
10 0.85 0.15 5 14 3 12 6 0.0159787 0.0160214 0.0160000
14 0.75 0.15 5 21 3 18 4 0.0159787 0.0160214 0.0160000
10 0.85 0.15 5 21 3 19 6 0.0159787 0.0160214 0.0160000
10 0.85 0.20 3 14 1 15 5 0.0146471 0.0150479 0.0148448
10 0.85 0.20 3 21 1 26 2 0.0146471 0.0150479 0.0148448
10 0.85 0.20 3 14 3 11 5 0.0146471 0.0150479 0.0148448
10 0.85 0.20 3 21 3 20 5 0.0146471 0.0150479 0.0148448
12 0.75 0.20 7 14 1 16 3 0.0146471 0.0148048 0.0147256
12 0.75 0.20 7 21 1 20 3 0.0146471 0.0148048 0.0147256
12 0.75 0.20 7 14 3 11 6 0.0146471 0.0148048 0.0147256
12 0.75 0.20 7 21 3 14 6 0.0146471 0.0148048 0.0147256
10 0.75 0.20 7 14 1 12 3 0.0133156 0.0134590 0.0133869
10 0.75 0.20 7 21 1 18 6 0.0133156 0.0134590 0.0133869
10 0.75 0.20 7 14 3 10 6 0.0133156 0.0134590 0.0133869
10 0.75 0.20 7 21 3 15 6 0.0133156 0.0134590 0.0133869
7 0.85 0.15 5 14 1 12 5 0.0133156 0.0133511 0.0133333
14 0.75 0.15 3 14 1 17 2 0.0133156 0.0133511 0.0133333
7 0.85 0.15 5 21 1 20 5 0.0133156 0.0133511 0.0133333
14 0.75 0.15 3 21 1 26 2 0.0133156 0.0133511 0.0133333
7 0.85 0.15 5 14 3 10 5 0.0133156 0.0133511 0.0133333
14 0.75 0.15 3 14 3 10 4 0.0133156 0.0133511 0.0133333
7 0.85 0.15 5 21 3 17 5 0.0133156 0.0133511 0.0133333
14 0.75 0.15 3 21 3 16 4 0.0133156 0.0133511 0.0133333
14 0.75 0.10 5 14 1 15 2 0.0133156 0.0133156 0.0133156
14 0.75 0.10 5 21 1 19 2 0.0133156 0.0133156 0.0133156
14 0.75 0.10 5 14 3 10 5 0.0133156 0.0133156 0.0133156
14 0.75 0.10 5 21 3 13 4 0.0133156 0.0133156 0.0133156
7 0.85 0.10 5 14 1 11 5 0.0119840 0.0120160 0.0120000
7 0.85 0.10 5 21 1 19 5 0.0119840 0.0120160 0.0120000
7 0.85 0.10 5 14 3 9 5 0.0119840 0.0120160 0.0120000
7 0.85 0.10 5 21 3 15 5 0.0119840 0.0120160 0.0120000
12 0.75 0.10 7 14 1 11 10 0.0119840 0.0119840 0.0119840
14 0.75 0.10 3 14 1 14 5 0.0119840 0.0119840 0.0119840
12 0.75 0.10 7 21 1 14 10 0.0119840 0.0119840 0.0119840
14 0.75 0.10 3 21 1 18 5 0.0119840 0.0119840 0.0119840
12 0.75 0.10 7 14 3 9 10 0.0119840 0.0119840 0.0119840
14 0.75 0.10 3 14 3 9 5 0.0119840 0.0119840 0.0119840
12 0.75 0.10 7 21 3 12 10 0.0119840 0.0119840 0.0119840
14 0.75 0.10 3 21 3 12 4 0.0119840 0.0119840 0.0119840
10 0.85 0.15 3 14 1 12 3 0.0106525 0.0106809 0.0106667
10 0.85 0.15 3 21 1 23 3 0.0106525 0.0106809 0.0106667
10 0.85 0.15 3 14 3 8 5 0.0106525 0.0106809 0.0106667
10 0.85 0.15 3 21 3 16 5 0.0106525 0.0106809 0.0106667
12 0.75 0.15 7 14 1 11 3 0.0106525 0.0106667 0.0106596
12 0.75 0.15 7 21 1 17 3 0.0106525 0.0106667 0.0106596
12 0.75 0.15 7 14 3 8 8 0.0106525 0.0106667 0.0106596
12 0.75 0.15 7 21 3 13 5 0.0106525 0.0106667 0.0106596
10 0.85 0.10 5 14 1 11 12 0.0106525 0.0106525 0.0106525
10 0.85 0.10 5 21 1 19 6 0.0106525 0.0106525 0.0106525
10 0.85 0.10 5 14 3 8 6 0.0106525 0.0106525 0.0106525
10 0.85 0.10 5 21 3 15 6 0.0106525 0.0106525 0.0106525
12 0.75 0.20 5 14 1 11 3 0.0093209 0.0094213 0.0093708
12 0.75 0.20 3 14 1 11 3 0.0093209 0.0094213 0.0093708
12 0.75 0.20 5 21 1 15 3 0.0093209 0.0094213 0.0093708
12 0.75 0.20 3 21 1 14 3 0.0093209 0.0094213 0.0093708
12 0.75 0.20 5 14 3 7 10 0.0093209 0.0094213 0.0093708
12 0.75 0.20 3 14 3 7 10 0.0093209 0.0094213 0.0093708
12 0.75 0.20 5 21 3 10 10 0.0093209 0.0094213 0.0093708
12 0.75 0.20 3 21 3 9 10 0.0093209 0.0094213 0.0093708
7 0.75 0.10 7 14 1 9 3 0.0093209 0.0093708 0.0093458
7 0.75 0.10 7 21 1 11 3 0.0093209 0.0093708 0.0093458
7 0.75 0.10 7 14 3 7 7 0.0093209 0.0093708 0.0093458
7 0.75 0.10 7 21 3 8 7 0.0093209 0.0093708 0.0093458
7 0.75 0.20 7 14 1 8 3 0.0079893 0.0080537 0.0080214
7 0.75 0.20 7 21 1 13 3 0.0079893 0.0080537 0.0080214
7 0.75 0.20 7 14 3 6 7 0.0079893 0.0080537 0.0080214
7 0.75 0.20 7 21 3 9 7 0.0079893 0.0080537 0.0080214
7 0.75 0.15 7 14 1 7 3 0.0079893 0.0080321 0.0080107
7 0.75 0.15 7 21 1 11 3 0.0079893 0.0080321 0.0080107
7 0.75 0.15 7 14 3 6 7 0.0079893 0.0080321 0.0080107
7 0.75 0.15 7 21 3 8 7 0.0079893 0.0080321 0.0080107
14 0.50 0.20 7 14 1 8 4 0.0079893 0.0080000 0.0079947
14 0.50 0.20 7 21 1 10 4 0.0079893 0.0080000 0.0079947
14 0.50 0.20 7 14 3 6 4 0.0079893 0.0080000 0.0079947
14 0.50 0.20 7 21 3 7 4 0.0079893 0.0080000 0.0079947
12 0.75 0.10 5 14 1 7 10 0.0079893 0.0079893 0.0079893
10 0.75 0.15 7 14 1 7 3 0.0079893 0.0079893 0.0079893
12 0.75 0.10 5 21 1 12 3 0.0079893 0.0079893 0.0079893
10 0.75 0.15 7 21 1 14 6 0.0079893 0.0079893 0.0079893
12 0.75 0.10 5 14 3 6 10 0.0079893 0.0079893 0.0079893
10 0.75 0.15 7 14 3 6 11 0.0079893 0.0079893 0.0079893
12 0.75 0.10 5 21 3 8 10 0.0079893 0.0079893 0.0079893
10 0.75 0.15 7 21 3 12 6 0.0079893 0.0079893 0.0079893
14 0.50 0.20 5 14 1 6 4 0.0066578 0.0066667 0.0066622
12 0.75 0.15 5 14 1 8 3 0.0066578 0.0066667 0.0066622
12 0.75 0.15 3 14 1 8 3 0.0066578 0.0066667 0.0066622
14 0.50 0.20 5 21 1 8 4 0.0066578 0.0066667 0.0066622
12 0.75 0.15 5 21 1 14 3 0.0066578 0.0066667 0.0066622
12 0.75 0.15 3 21 1 14 3 0.0066578 0.0066667 0.0066622
14 0.50 0.20 5 14 3 5 4 0.0066578 0.0066667 0.0066622
12 0.75 0.15 5 14 3 5 10 0.0066578 0.0066667 0.0066622
12 0.75 0.15 3 14 3 5 10 0.0066578 0.0066667 0.0066622
14 0.50 0.20 5 21 3 6 4 0.0066578 0.0066667 0.0066622
12 0.75 0.15 5 21 3 9 10 0.0066578 0.0066667 0.0066622
12 0.75 0.15 3 21 3 8 10 0.0066578 0.0066667 0.0066622
10 0.75 0.10 7 14 1 8 6 0.0066578 0.0066578 0.0066578
14 0.50 0.15 7 14 1 8 4 0.0066578 0.0066578 0.0066578
12 0.75 0.10 3 14 1 5 10 0.0066578 0.0066578 0.0066578
10 0.75 0.10 7 21 1 13 6 0.0066578 0.0066578 0.0066578
14 0.50 0.15 7 21 1 10 4 0.0066578 0.0066578 0.0066578
12 0.75 0.10 3 21 1 10 10 0.0066578 0.0066578 0.0066578
10 0.75 0.10 7 14 3 5 11 0.0066578 0.0066578 0.0066578
14 0.50 0.15 7 14 3 5 4 0.0066578 0.0066578 0.0066578
12 0.75 0.10 3 14 3 5 10 0.0066578 0.0066578 0.0066578
10 0.75 0.10 7 21 3 9 6 0.0066578 0.0066578 0.0066578
14 0.50 0.15 7 21 3 6 4 0.0066578 0.0066578 0.0066578
12 0.75 0.10 3 21 3 6 10 0.0066578 0.0066578 0.0066578
7 0.85 0.20 3 14 1 7 2 0.0053262 0.0053981 0.0053619
7 0.85 0.20 3 21 1 12 6 0.0053262 0.0053981 0.0053619
7 0.85 0.20 3 14 3 4 6 0.0053262 0.0053981 0.0053619
7 0.85 0.20 3 21 3 8 6 0.0053262 0.0053981 0.0053619
14 0.50 0.20 3 14 1 5 4 0.0053262 0.0053333 0.0053298
14 0.50 0.20 3 21 1 7 4 0.0053262 0.0053333 0.0053298
14 0.50 0.20 3 14 3 4 4 0.0053262 0.0053333 0.0053298
14 0.50 0.20 3 21 3 5 4 0.0053262 0.0053333 0.0053298
14 0.50 0.10 7 14 1 8 4 0.0053262 0.0053262 0.0053262
14 0.50 0.10 7 21 1 10 4 0.0053262 0.0053262 0.0053262
14 0.50 0.10 7 14 3 4 4 0.0053262 0.0053262 0.0053262
14 0.50 0.10 7 21 3 4 4 0.0053262 0.0053262 0.0053262
10 0.75 0.20 5 14 1 4 3 0.0039947 0.0040377 0.0040161
10 0.75 0.20 3 14 1 4 3 0.0039947 0.0040377 0.0040161
10 0.75 0.20 5 21 1 13 6 0.0039947 0.0040377 0.0040161
10 0.75 0.20 3 21 1 11 6 0.0039947 0.0040377 0.0040161
10 0.75 0.20 5 14 3 3 6 0.0039947 0.0040377 0.0040161
10 0.75 0.20 3 14 3 3 6 0.0039947 0.0040377 0.0040161
10 0.75 0.20 5 21 3 9 6 0.0039947 0.0040377 0.0040161
10 0.75 0.20 3 21 3 7 6 0.0039947 0.0040377 0.0040161
14 0.50 0.10 5 14 1 6 4 0.0039947 0.0039947 0.0039947
14 0.50 0.15 5 14 1 5 4 0.0039947 0.0039947 0.0039947
10 0.50 0.20 7 14 1 4 7 0.0039947 0.0039947 0.0039947
10 0.85 0.10 3 14 1 3 5 0.0039947 0.0039947 0.0039947
14 0.50 0.10 5 21 1 8 4 0.0039947 0.0039947 0.0039947
14 0.50 0.15 5 21 1 7 4 0.0039947 0.0039947 0.0039947
10 0.50 0.20 7 21 1 5 2 0.0039947 0.0039947 0.0039947
10 0.85 0.10 3 21 1 11 8 0.0039947 0.0039947 0.0039947
14 0.50 0.10 5 14 3 3 4 0.0039947 0.0039947 0.0039947
14 0.50 0.15 5 14 3 3 4 0.0039947 0.0039947 0.0039947
10 0.50 0.20 7 14 3 3 7 0.0039947 0.0039947 0.0039947
10 0.85 0.10 3 14 3 3 5 0.0039947 0.0039947 0.0039947
14 0.50 0.10 5 21 3 3 4 0.0039947 0.0039947 0.0039947
14 0.50 0.15 5 21 3 4 4 0.0039947 0.0039947 0.0039947
10 0.50 0.20 7 21 3 3 7 0.0039947 0.0039947 0.0039947
10 0.85 0.10 3 21 3 10 15 0.0039947 0.0039947 0.0039947
10 0.50 0.20 5 14 1 3 2 0.0026631 0.0026631 0.0026631
12 0.50 0.20 5 14 1 3 4 0.0026631 0.0026631 0.0026631
12 0.50 0.20 7 14 1 3 4 0.0026631 0.0026631 0.0026631
10 0.50 0.20 3 14 1 3 2 0.0026631 0.0026631 0.0026631
7 0.85 0.10 3 14 1 4 2 0.0026631 0.0026631 0.0026631
14 0.50 0.10 3 14 1 5 4 0.0026631 0.0026631 0.0026631
7 0.85 0.15 3 14 1 4 -19 0.0026631 0.0026631 0.0026631
14 0.50 0.15 3 14 1 4 4 0.0026631 0.0026631 0.0026631
10 0.50 0.20 5 21 1 4 2 0.0026631 0.0026631 0.0026631
12 0.50 0.20 5 21 1 5 4 0.0026631 0.0026631 0.0026631
12 0.50 0.20 7 21 1 5 4 0.0026631 0.0026631 0.0026631
10 0.50 0.20 3 21 1 4 2 0.0026631 0.0026631 0.0026631
7 0.85 0.10 3 21 1 13 3 0.0026631 0.0026631 0.0026631
14 0.50 0.10 3 21 1 7 4 0.0026631 0.0026631 0.0026631
7 0.85 0.15 3 21 1 12 5 0.0026631 0.0026631 0.0026631
14 0.50 0.15 3 21 1 6 4 0.0026631 0.0026631 0.0026631
10 0.50 0.20 5 14 3 2 6 0.0026631 0.0026631 0.0026631
12 0.50 0.20 5 14 3 2 4 0.0026631 0.0026631 0.0026631
12 0.50 0.20 7 14 3 2 4 0.0026631 0.0026631 0.0026631
10 0.50 0.20 3 14 3 2 6 0.0026631 0.0026631 0.0026631
7 0.85 0.10 3 14 3 2 6 0.0026631 0.0026631 0.0026631
14 0.50 0.10 3 14 3 2 4 0.0026631 0.0026631 0.0026631
7 0.85 0.15 3 14 3 2 6 0.0026631 0.0026631 0.0026631
14 0.50 0.15 3 14 3 2 4 0.0026631 0.0026631 0.0026631
10 0.50 0.20 5 21 3 2 6 0.0026631 0.0026631 0.0026631
12 0.50 0.20 5 21 3 4 4 0.0026631 0.0026631 0.0026631
12 0.50 0.20 7 21 3 4 4 0.0026631 0.0026631 0.0026631
10 0.50 0.20 3 21 3 2 6 0.0026631 0.0026631 0.0026631
7 0.85 0.10 3 21 3 8 10 0.0026631 0.0026631 0.0026631
14 0.50 0.10 3 21 3 2 4 0.0026631 0.0026631 0.0026631
7 0.85 0.15 3 21 3 8 5 0.0026631 0.0026631 0.0026631
14 0.50 0.15 3 21 3 3 4 0.0026631 0.0026631 0.0026631
10 0.75 0.10 5 14 1 3 3 0.0013316 0.0013316 0.0013316
10 0.75 0.15 5 14 1 2 3 0.0013316 0.0013316 0.0013316
10 0.50 0.15 5 14 1 2 2 0.0013316 0.0013316 0.0013316
12 0.50 0.15 5 14 1 3 2 0.0013316 0.0013316 0.0013316
10 0.50 0.15 7 14 1 2 2 0.0013316 0.0013316 0.0013316
12 0.50 0.15 7 14 1 3 2 0.0013316 0.0013316 0.0013316
12 0.50 0.20 3 14 1 2 2 0.0013316 0.0013316 0.0013316
10 0.75 0.10 3 14 1 2 3 0.0013316 0.0013316 0.0013316
10 0.75 0.15 3 14 1 2 3 0.0013316 0.0013316 0.0013316
10 0.50 0.15 3 14 1 2 2 0.0013316 0.0013316 0.0013316
12 0.50 0.15 3 14 1 3 2 0.0013316 0.0013316 0.0013316
10 0.75 0.10 5 21 1 9 3 0.0013316 0.0013316 0.0013316
10 0.75 0.15 5 21 1 10 3 0.0013316 0.0013316 0.0013316
10 0.50 0.15 5 21 1 3 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 5 21 1 5 4 0.0013316 0.0013316 0.0013316
10 0.50 0.15 7 21 1 3 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 7 21 1 5 4 0.0013316 0.0013316 0.0013316
12 0.50 0.20 3 21 1 4 4 0.0013316 0.0013316 0.0013316
10 0.75 0.10 3 21 1 7 3 0.0013316 0.0013316 0.0013316
10 0.75 0.15 3 21 1 8 3 0.0013316 0.0013316 0.0013316
10 0.50 0.15 3 21 1 3 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 3 21 1 5 4 0.0013316 0.0013316 0.0013316
10 0.75 0.10 5 14 3 1 12 0.0013316 0.0013316 0.0013316
10 0.75 0.15 5 14 3 1 12 0.0013316 0.0013316 0.0013316
10 0.50 0.15 5 14 3 1 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 5 14 3 1 7 0.0013316 0.0013316 0.0013316
10 0.50 0.15 7 14 3 1 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 7 14 3 1 7 0.0013316 0.0013316 0.0013316
12 0.50 0.20 3 14 3 1 5 0.0013316 0.0013316 0.0013316
10 0.75 0.10 3 14 3 1 12 0.0013316 0.0013316 0.0013316
10 0.75 0.15 3 14 3 1 12 0.0013316 0.0013316 0.0013316
10 0.50 0.15 3 14 3 1 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 3 14 3 1 7 0.0013316 0.0013316 0.0013316
10 0.75 0.10 5 21 3 3 -2 0.0013316 0.0013316 0.0013316
10 0.75 0.15 5 21 3 5 -2 0.0013316 0.0013316 0.0013316
10 0.50 0.15 5 21 3 2 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 5 21 3 3 4 0.0013316 0.0013316 0.0013316
10 0.50 0.15 7 21 3 2 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 7 21 3 3 4 0.0013316 0.0013316 0.0013316
12 0.50 0.20 3 21 3 3 4 0.0013316 0.0013316 0.0013316
10 0.75 0.10 3 21 3 3 -2 0.0013316 0.0013316 0.0013316
10 0.75 0.15 3 21 3 3 -2 0.0013316 0.0013316 0.0013316
10 0.50 0.15 3 21 3 2 14 0.0013316 0.0013316 0.0013316
12 0.50 0.15 3 21 3 3 4 0.0013316 0.0013316 0.0013316
7 0.75 0.20 5 14 1 1 2 0.0000000 0.0000000 NA
7 0.50 0.20 5 14 1 0 -1 0.0000000 0.0000000 NA
7 0.75 0.10 5 14 1 1 3 0.0000000 0.0000000 NA
10 0.50 0.10 5 14 1 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 5 14 1 1 2 0.0000000 0.0000000 NA
7 0.50 0.10 5 14 1 0 -1 0.0000000 0.0000000 NA
7 0.75 0.15 5 14 1 1 3 0.0000000 0.0000000 NA
7 0.50 0.15 5 14 1 0 -1 0.0000000 0.0000000 NA
7 0.50 0.20 7 14 1 0 -1 0.0000000 0.0000000 NA
10 0.50 0.10 7 14 1 1 2 0.0000000 0.0000000 NA
12 0.50 0.10 7 14 1 1 2 0.0000000 0.0000000 NA
7 0.50 0.10 7 14 1 0 -1 0.0000000 0.0000000 NA
7 0.50 0.15 7 14 1 0 -1 0.0000000 0.0000000 NA
7 0.75 0.20 3 14 1 2 2 0.0000000 0.0000000 NA
7 0.50 0.20 3 14 1 0 -1 0.0000000 0.0000000 NA
7 0.75 0.10 3 14 1 1 -20 0.0000000 0.0000000 NA
10 0.50 0.10 3 14 1 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 3 14 1 1 2 0.0000000 0.0000000 NA
7 0.50 0.10 3 14 1 0 -1 0.0000000 0.0000000 NA
7 0.75 0.15 3 14 1 0 -1 0.0000000 0.0000000 NA
7 0.50 0.15 3 14 1 0 -1 0.0000000 0.0000000 NA
7 0.75 0.20 5 21 1 4 -13 0.0000000 0.0000000 NA
7 0.50 0.20 5 21 1 2 -7 0.0000000 0.0000000 NA
7 0.75 0.10 5 21 1 5 3 0.0000000 0.0000000 NA
10 0.50 0.10 5 21 1 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 5 21 1 2 -76 0.0000000 0.0000000 NA
7 0.50 0.10 5 21 1 3 -44 0.0000000 0.0000000 NA
7 0.75 0.15 5 21 1 4 3 0.0000000 0.0000000 NA
7 0.50 0.15 5 21 1 3 -44 0.0000000 0.0000000 NA
7 0.50 0.20 7 21 1 2 19 0.0000000 0.0000000 NA
10 0.50 0.10 7 21 1 1 2 0.0000000 0.0000000 NA
12 0.50 0.10 7 21 1 2 -76 0.0000000 0.0000000 NA
7 0.50 0.10 7 21 1 2 19 0.0000000 0.0000000 NA
7 0.50 0.15 7 21 1 2 19 0.0000000 0.0000000 NA
7 0.75 0.20 3 21 1 4 6 0.0000000 0.0000000 NA
7 0.50 0.20 3 21 1 1 -7 0.0000000 0.0000000 NA
7 0.75 0.10 3 21 1 2 6 0.0000000 0.0000000 NA
10 0.50 0.10 3 21 1 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 3 21 1 2 -76 0.0000000 0.0000000 NA
7 0.50 0.10 3 21 1 1 -7 0.0000000 0.0000000 NA
7 0.75 0.15 3 21 1 2 6 0.0000000 0.0000000 NA
7 0.50 0.15 3 21 1 1 -7 0.0000000 0.0000000 NA
7 0.75 0.20 5 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.20 5 14 3 0 -1 0.0000000 0.0000000 NA
7 0.75 0.10 5 14 3 0 -1 0.0000000 0.0000000 NA
10 0.50 0.10 5 14 3 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 5 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.10 5 14 3 0 -1 0.0000000 0.0000000 NA
7 0.75 0.15 5 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.15 5 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.20 7 14 3 0 -1 0.0000000 0.0000000 NA
10 0.50 0.10 7 14 3 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 7 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.10 7 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.15 7 14 3 0 -1 0.0000000 0.0000000 NA
7 0.75 0.20 3 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.20 3 14 3 0 -1 0.0000000 0.0000000 NA
7 0.75 0.10 3 14 3 0 -1 0.0000000 0.0000000 NA
10 0.50 0.10 3 14 3 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 3 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.10 3 14 3 0 -1 0.0000000 0.0000000 NA
7 0.75 0.15 3 14 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.15 3 14 3 0 -1 0.0000000 0.0000000 NA
7 0.75 0.20 5 21 3 1 -13 0.0000000 0.0000000 NA
7 0.50 0.20 5 21 3 2 -7 0.0000000 0.0000000 NA
7 0.75 0.10 5 21 3 2 7 0.0000000 0.0000000 NA
10 0.50 0.10 5 21 3 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 5 21 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.10 5 21 3 2 -7 0.0000000 0.0000000 NA
7 0.75 0.15 5 21 3 1 12 0.0000000 0.0000000 NA
7 0.50 0.15 5 21 3 2 -7 0.0000000 0.0000000 NA
7 0.50 0.20 7 21 3 2 19 0.0000000 0.0000000 NA
10 0.50 0.10 7 21 3 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 7 21 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.10 7 21 3 2 19 0.0000000 0.0000000 NA
7 0.50 0.15 7 21 3 2 19 0.0000000 0.0000000 NA
7 0.75 0.20 3 21 3 2 6 0.0000000 0.0000000 NA
7 0.50 0.20 3 21 3 1 -7 0.0000000 0.0000000 NA
7 0.75 0.10 3 21 3 2 6 0.0000000 0.0000000 NA
10 0.50 0.10 3 21 3 0 -1 0.0000000 0.0000000 NA
12 0.50 0.10 3 21 3 0 -1 0.0000000 0.0000000 NA
7 0.50 0.10 3 21 3 1 -7 0.0000000 0.0000000 NA
7 0.75 0.15 3 21 3 1 6 0.0000000 0.0000000 NA
7 0.50 0.15 3 21 3 1 -7 0.0000000 0.0000000 NA
plot_list=vector("list", performance_df$Number_Success_Examples[1])
  fb_survey_cases_indicator_list = get_increase_points(case_list = fb_survey2$cases, 
                                                     indicator_list = fb_survey2$indicator,
                                                    local_bandwidth = 14,
                                                    local_quantile_threshold = 0.85,
                                                    local_threshold=0.2,
                                                    local_period=7)
  fb_survey_success_examples = get_success_examples(case_indicator_list = fb_survey_cases_indicator_list, success_window=14,min_success_window=1)
  leadingness_dist=get_leading_indicator_day_distribution(success_examples = fb_survey_success_examples,final_cases_indicator_list = fb_survey_cases_indicator_list)

# pdf("success_examples_best_parameters_2_09_21.pdf")
# for(i in 1:length(plot_list))
# {
#   county_name = fb_survey_success_examples[[i]]
#   plot_list[[i]]<-plot_signals(case_indicator_list = fb_survey_cases_indicator_list, county_fips = fb_survey_success_examples[[i]],
#              ylab1 = "New COVID-19 Cases",
#              ylab2="FB Survey", smooth_and_show_increase_point = TRUE)
# }
# library(gridExtra)
# ggsave(
#    filename = "success_examples_best_parameters_2_09_21.pdf", 
#    plot = marrangeGrob(plot_list, nrow=2, ncol=2), 
# )
# 
# dev.off()
  
for(i in 1:length(plot_list))
{
  county_name = fb_survey_success_examples[[i]]
  plot_list[[i]]<-plot_signals(case_indicator_list = fb_survey_cases_indicator_list, county_fips = fb_survey_success_examples[[i]],
             ylab1 = "New COVID-19 Cases",
             ylab2="FB Survey", smooth_and_show_increase_point = TRUE)
  print(plot_list[[i]])

}

## Warning in grep_lookup(key = name, keys = df$NAME, values = df$ABBR, ignore.case
## = ignore.case, : Some inputs were not uniquely matched; returning only the first
## match in each case.

## Warning in grep_lookup(key = name, keys = df$NAME, values = df$ABBR, ignore.case
## = ignore.case, : Some inputs were not uniquely matched; returning only the first
## match in each case.

## Warning in grep_lookup(key = name, keys = df$NAME, values = df$ABBR, ignore.case
## = ignore.case, : Some inputs were not uniquely matched; returning only the first
## match in each case.

fb_survey_cases_indicator_list = get_increase_points(case_list = fb_survey2$cases, 
                                                     indicator_list = fb_survey2$indicator,
                                                    local_bandwidth = 12,
                                                    local_quantile_threshold = 0.75,
                                                    local_threshold=0.2,
                                                    local_period=0)
all_guessers=generate_competitors_get_scores(final_cases_indicator_list=fb_survey_cases_indicator_list)
first_elem=all_guessers[[1]]
    par(mfrow=c(3,2))
    plot(first_elem$time_value, first_elem$case_value, col=ifelse(first_elem$case_rise_point==1, 'red','black'), pch=20, xlab = "Case", ylab = "Date",
         main = "Case Rise Point")
    plot(first_elem$time_value, first_elem$case_value, col=ifelse(first_elem$indicator_rise_point==1, 'red','black'), pch=20,xlab = "Case", ylab = "Date",
         main = "Indicator Rise Point")
    plot(first_elem$time_value, first_elem$case_value, col=ifelse(first_elem$random_guesser==1, 'red','black'), pch=20, xlab = "Case", ylab = "Date",
         main = "Random Guesser")
    plot(first_elem$time_value, first_elem$case_value, col=ifelse(first_elem$case_first_deriv_guesser==1, 'red','black'), pch=20, xlab = "Case", ylab = "Date",
         main = "Case First Derivative > 0")
    plot(first_elem$time_value, first_elem$case_value, col=ifelse(first_elem$indicator_first_deriv==1, 'red','black'),pch=20, xlab = "Case", ylab = "Date",
         main = "Indicator First Derivative > 0")